import type R from '@/types/conduit/R'
import type Coupon from '@/types/entity/Coupon'
import type CouponProduct from '@/types/entity/CouponProduct'
import type { CouponOrderPayment, CouponCoreInfo } from '@/types/response/coupon'
import request from '@/utils/request'
// 获取平台优惠券
export const platformProvincialWalletList = (): Promise<R<CouponProduct[]>> =>
  request({
    url: `/coupon/coupon-product/platform-provincial-wallet`,
    method: 'GET'
  })

// 创建优惠券购买订单
export const createCouponOrder = (productOrderId: number): Promise<R<CouponOrderPayment>> =>
  request({
    url: `/coupon/coupon-order/create/${productOrderId}`,
    method: 'POST'
  })
// 模拟支付优惠券订单
export const paymentCouponOrder = (productOrderId: number): Promise<R<null>> =>
  request({
    url: `/coupon/coupon-order/payment/${productOrderId}`,
    method: 'POST'
  })
// 查询我的平台优惠券
export const myPlatformCoupons = (shopId?: number): Promise<R<CouponCoreInfo[]>> =>
  request({
    url: `/coupon/coupon/my-platform-coupons`,
    params: { shopId },
    method: 'GET'
  })
// 优惠券膨胀
export const expandCoupon = (couponId: number): Promise<R<null>> =>
  request({
    url: `/coupon/coupon/expand-coupon/${couponId}`,
    method: 'POST'
  })
/**
 * 查询用户可领取/已拥有的指定店铺优惠券
 */
export const applicableCouponsForShop = (shopId: number): Promise<R<Array<Coupon>>> =>
  request({
    url: `/coupon/coupon/applicable-coupons-for-shop/${shopId}`,
    method: 'GET'
  })

/**
 * 查询用户拥有的所有可用的店铺券
 */
export const getAllAvailableShopCoupons = (): Promise<R<Array<CouponCoreInfo>>> =>
  request({
    url: `/coupon/coupon/all-available-shop-coupons`,
    method: 'GET'
  })
/**
 * 查询指定batchId列表的券信息-用于使用券页面券的领取
 */
export const queryCouponForReceive = (shopId: number, batchIds: string[]): Promise<R<CouponCoreInfo[]>> =>
  request({
    url: `/coupon/coupon/receive-by`,
    method: 'GET',
    params: { shopId, batchIds: batchIds.join(',') }
  })

/**
 * 用户领取指定店铺内优惠券
 */
export const receiveShopPublicCoupon = (batchId: number): Promise<R<null>> =>
  request({
    url: `/coupon/coupon-batch/receive-shop-public-coupon/${batchId}`,
    method: 'POST'
  })
